home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / q.arc / Q.C next >
Text File  |  1989-11-12  |  5KB  |  179 lines

  1. /**************************************************************************/
  2. /*    Q                                                                 */
  3. /*    by Morgan Adair                                                   */
  4. /*                                                                        */
  5. /*    Displays a list of print jobs for specified print queue(s)        */
  6. /**************************************************************************/
  7.  
  8. #include <nit.h>
  9. #include <nitq.h>
  10.  
  11. main(argc, argv)
  12.  
  13. int    argc;
  14. char    *argv[];
  15.  
  16. {
  17.     int        cCode;
  18.     int        queueFound = 0;
  19.     char        serverName[48];
  20.     WORD        connectionID;
  21.     char        searchName[48];
  22.     long        objectID = -1;
  23.     char        objectName[48];
  24.     int        objectType;
  25.     char        objectHasProperties;
  26.     char        objectFlag;
  27.     char        objectSecurity;
  28.  
  29.     if (argc < 2) {
  30.         /* no command line arguments, use default file server */
  31.         connectionID = GetDefaultConnectionID();
  32.         GetFileServerName(connectionID, serverName);
  33.  
  34.     } else {
  35.         /* a file server was specified, look for queues on it */
  36.         strcpy(serverName, argv[1]);
  37.  
  38.         if (!(cCode = GetConnectionID(serverName, &connectionID)))
  39.             SetPreferredConnectionID(connectionID);
  40.         else {
  41.             printf("No connection to server %s\n", serverName);
  42.             Syntax();
  43.             exit(-1);
  44.         }
  45.     }
  46.  
  47.     if (argc == 3) {
  48.         /* both a file server name and print queue name were
  49.            specified, handle just the one queue */
  50.         strupr(argv[2]);
  51.         if (!(cCode = ScanBinderyObject(argv[2], OT_PRINT_QUEUE,
  52.                        &objectID, objectName,
  53.                        &objectType, &objectHasProperties,
  54.                        &objectFlag, &objectSecurity))) {
  55.  
  56.             printf("Queue      Job # \t\tOwner[Station #]   \tJob Size (bytes)\n\n");
  57.             CheckQueue(objectName, objectID);
  58.  
  59.         } else {
  60.             printf("Queue %s not found\n", argv[2]);
  61.             Syntax();
  62.             exit(-1);
  63.         }
  64.  
  65.     } else {
  66.         /* no queue name was specified, handle all queues on
  67.            preferred file server */
  68.  
  69.         strcpy(searchName, "*");
  70.  
  71.         do {    /* While finding queues on the file server */
  72.  
  73.             cCode = ScanBinderyObject(searchName, OT_PRINT_QUEUE,
  74.                            &objectID, objectName,
  75.                            &objectType, &objectHasProperties,
  76.                            &objectFlag, &objectSecurity);
  77.  
  78.             if (!cCode) {    /* Found a queue object */
  79.  
  80.                 if (!queueFound) {    /* First one I found */
  81.                     printf("Queue      Job # \t\tOwner[Station #]   \tJob Size (bytes)\n\n");
  82.                     queueFound = 1;
  83.                 }
  84.  
  85.                 CheckQueue(objectName, objectID);
  86.  
  87.             } else if (!queueFound) {    /* Didn't find any queues */
  88.                 printf("No queues found on server %s\n", serverName);
  89.                 Syntax();
  90.                 exit(-1);
  91.             }
  92.  
  93.         } while (!cCode);
  94.     }
  95. }
  96.  
  97.  
  98. CheckQueue(queueName, queueID)        /* list print jobs on specified queue */
  99. char    queueName[48];
  100. long    queueID;
  101. {
  102.  
  103. #define MAX_JOB_NUMS 250
  104.  
  105.     int        cCode;
  106.     int        jobCount;
  107.     int        i;
  108.     int        jobNumberList[MAX_JOB_NUMS];
  109.     JobStruct    job;
  110.     char        clientName[48];
  111.     int        clientType;
  112.     long        fileSize;
  113.     char        outString[80];
  114.     char        active[10];
  115.     char        errMsg[25];
  116.  
  117.     if (cCode = GetQueueJobList(queueID, &jobCount,
  118.                  jobNumberList, MAX_JOB_NUMS)) {
  119.  
  120.         /* an error getting the queue's job list */
  121.  
  122.         switch (cCode) {
  123.             case 150:    strcpy(errMsg, "Server out of memory");
  124.                     break;
  125.             case 211:    strcpy(errMsg, "No rights to queue");
  126.                     break;
  127.             default:    strcpy(errMsg, "Error getting job list");
  128.         }
  129.  
  130.         sprintf(outString, "%-10s %-25s\n", queueName, errMsg);
  131.  
  132.     } else if (jobCount == 0)
  133.         /* GetQueueJobList did not return error, but no jobs in queue */
  134.         sprintf(outString, "%-10s %-25s\n", queueName, "No jobs");
  135.  
  136.     else {
  137.         /* GetQueueJobList succeeded, and jobs in queue */
  138.         for (i=0; i<=jobCount-1; i++) {
  139.             /* the next three calls must succeed before displaying print
  140.                job data */
  141.             cCode = ReadQueueJobEntry(queueID, jobNumberList[i], &job);
  142.             cCode = (cCode | GetBinderyObjectName(job.clientIDNumber,
  143.                                      clientName,
  144.                                  &clientType));
  145.             cCode = (cCode | GetQueueJobsFileSize(queueID,
  146.                                   jobNumberList[i],
  147.                                   &fileSize));
  148.  
  149.             if (i>0)
  150.                 /* display queue name only with first job in list */
  151.                 strcpy(queueName, "");
  152.  
  153.             if (cCode)
  154.                 sprintf(outString, "%-10s %-5d\n", queueName,
  155.                     jobNumberList[i], "\tError getting data on job\n");
  156.             else {
  157.                 /* show whether job is active */
  158.                 if (job.serverIDNumber == 0L)
  159.                     strcpy(active, "");
  160.                 else
  161.                     strcpy(active, "(active)");
  162.  
  163.                 sprintf(outString, "%-10s  %-5d%8s %18s[%d] \t%10ld\n",
  164.                     queueName, jobNumberList[i], active, clientName,
  165.                     job.clientStation, fileSize);
  166.             }
  167.             printf(outString);
  168.         }
  169.         strcpy(outString, "");
  170.     }
  171.     printf(outString);
  172.     printf("\n");
  173. }
  174.  
  175. Syntax()
  176. {
  177.     printf("\tSyntax:  q <servername> <queuename>\n\n");
  178. }
  179.